// package com.tfswx.jcyw.cloudfiletest;
//
// import cn.ctyun.config.DomainConfig;
// import com.amazonaws.*;
// import com.amazonaws.auth.*;
// import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient;
// import com.amazonaws.services.identitymanagement.model.*;
// import com.amazonaws.services.s3.*;
// import com.amazonaws.services.s3.model.*;
// import com.amazonaws.services.s3.multipleupload.MultipleUpload;
// import com.amazonaws.services.s3.multipleupload.model.UploadFileRequest;
// import com.amazonaws.services.s3.transfer.TransferManager;
// import com.amazonaws.services.s3.transfer.Upload;
// import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;
// import com.amazonaws.services.securitytoken.model.*;
// import org.apache.commons.io.IOUtils;
//
// import java.io.*;
// import java.net.URL;
// import java.util.*;
// import java.util.regex.Matcher;
// import java.util.regex.Pattern;
//
// /**
//  * @author ricky
//  * @date 2022/7/30
//  */
//
// public class OOSTest {
//
//     private static String myBucketName = "bkt-hhhhtest";
//     private static String dstBucketName = "dstbucket";
//     private static String dstObjectName = "dstObject";
//     private static String objectInBucketKey2 = "httpd-2.4.38.tar.bz2";
//     private static String myLocation = "QingDao";
//
//     public static void main(String[] args) throws Exception{
//         CreateAccessKeyResult createAccessKeyResult = new CreateAccessKeyResult();
//
//         try {
//             AmazonS3 ossClient = getAmazonS3();
//             // AmazonS3 ossClient2 = getAmazonS3_hwl();
//             //AmazonS3 iamClient = getIamS3();
//             //AWSSecurityTokenServiceClient stsClient = getStSClient();
//             System.out.println("\n\n");
//             System.out.println("===========OOS Java Sample Boot OK!================\n\n\n");
//             //不使用V4签名
//             System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true");
//             //System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "false");
//             // test_generatePresignedUrlSts();
//             //testGetObject(ossClient2, TestConfig.bucketName, "test1.txt");
//
//             //OOSTest test = new OOSTest();
//             //test.testMultipartUpload(ossClient2);
//             //test.checkEndPoint();
//
//             //getSessionToken(stsClient);
//
//             //Service ######################################################################
//             //1	Service	GetService(ListBucket)
//             listBuckets(ossClient);
//
//             //2	Service	Get Regions#!#!
//             //getRegions(ossClient2);
//
//             //3	Bucket	Put Bucket#!#!
//             //putBucket(ossClient2);
//             //putBucket2(ossClient2);
//             //3	Bucket	Put Bucket#!#!
//             // puteBucketToLocation(ossClient2);
//             //putBucketToLocationWithAcl(ossClient);
//
//             //3	Bucket	Put Bucket#!#!
//             //putBucketToMultiDataLocation(ossClient);
//
//             //4	Bucket	Get Bucket location
//             //getBucketLocation(ossClient);
//
//             //5	Bucket	Get bucket acl
//             //getBucketAcl(ossClient);
//
//             //6	Bucket	GET Bucket (List Objects)
//             //listObjects(ossClient);
//             //listAndDelObjects(ossClient, "javatest124");
//
//             //7	Bucket	Delete bucket
//             //deleteBucket(ossClient);
//
//             //8	Bucket	Put Bucket Policy
//             //setBucketPolicy(ossClient);
//
//             //9	Bucket	Get Bucket Policy
//             //getBucketPolicy(ossClient2);
//
//             //10	Bucket	Delete bucket Policy
//             //deleteBucketPolicy(ossClient);
//
//             //11	Bucket	Put Bucket WebSite
//             //putBucketWebsite(ossClient);
//
//             //12	Bucket	Get Bucket WebSite
//             //getBucketWebsite(ossClient);
//
//             //13	Bucket	Delete bucket WebSite
//             //deleteBucketWebsite(ossClient);
//
//             //14	Bucket	List Multipart Uploads
//             //listMultipartUploads(ossClient);
//
//             //15	Bucket	Put Bucket Logging
//             //putBucketLogging(ossClient);
//
//             //16	Bucket	Get Bucket Logging
//             //getBucketLogging(ossClient);
//
//             //17	Bucket	Head Bucket
//             //doesBucketExist(ossClient2);
//             //headBucket(ossClient2);
//             //headBucket_noExist(ossClient2);
//             //18	Bucket	Put Bucket Lifecycle
//             //putBucketLifecycle(ossClient);
//
//             //19	Bucket	Get Bucket Lifecycle
//             //getBucketLifecycle(ossClient);
//
//             //20	Bucket	Delete Bucket Lifecycle
//             //deleteBucketLifecycle(ossClient);
//
//             //21	Bucket	Put Bucket accelerate
//             //putAccelerate(ossClient);
//
//             //22	Bucket	Get Bucket accelerate
//             //getAccelerate(ossClient);
//
//             //23	Bucket	PUT Bucket cors
//             // putBucketCors(ossClient);
//
//             //24	Bucket	GET Bucket cors
//             //getBucketCors(ossClient);
//
//             //25	Bucket	DELETE Bucket cors
//             //deleteBucketCors(ossClient);
//
//
//             //Object ######################################################################
//             //29	Object	Put Object
//             //putObject(ossClient2);
//
//             //putObjectToLocation(ossClient);
//
//             //30	Object	Get Object
//             //getObject(ossClient2);
//
//             //31	Object	Delete Object
//             //deleteObject(ossClient2);
//
//             //32	Object	PUT Object - Copy
//             //copyObject(ossClient2);
//
//
//             //33	Object	Initial Multipart Upload
//             //puteBucketToLocation(ossClient,myBucketName);
//             //String uploadIdString = initiateMultipartUpload(ossClient2);
//
//             //34	Object	Upload Part
//             //String etagString = uploadPart(ossClient,uploadIdString);
//
//             //35	Object	Complete Multipart Upload
//             //completeMultipartUpload(ossClient,uploadIdString,etagString);
//
//             //37	Object	List Part
//             //listParts(ossClient,uploadIdString);
//
//             //36	Object	Abort Multipart Upload
//             //abortMultipartUpload(ossClient,uploadIdString);
//
//             //38	Object	Copy Part
//             //puteBucketToLocation(ossClient, dstBucketName);
//             //copyPart(ossClient,uploadIdString);
//
//             //40	Object	Delete Multiple Objects
//             //deleteObjects(ossClient2);
//
//             //44	Object	生成共享链接
//             //generatePresignedUrl(ossClient2);
//
//             //initailPart(ossClient);
//
//             //45	Object	HEAD Object
//             //headObject(ossClient);
//
//             //Key    ######################################################################
//             //46	Key	CreateAccessKey
//             //createAccessKey(iamClient);
//
//             //47	Key	DeleteAccessKey
//             //deleteAccessKey(iamClient);
//
//             //48	Key	UpdateAccessKey
//             //updateAccessKey(iamClient);
//
//             //49	Key	ListAccessKey
//             //listAccessKey(iamClient);
//
//             //101 multiUpload
//             //multiUpload(ossClient2);
//             //generatePresignedUrl(ossClient);
//
//             //102 generatePresignedUrlForListPartV2
//             //generatePresignedUrlForListPartV2(ossClient);
//
//             // generatePresignedUrlForObject(ossClient2);
//             //######################### Very Good! Finished !##############################
//
//             //testMultiUploadCopy(ossClient);
//
//             //testTransferManager(ossClient2);
//
//             //testAbortMultipartUploads(ossClient2);
//
//             System.out.println("                congratulation!                   \n\n\n");
//             System.out.println("===========OOS Java Sample Test OK!================\n");
//         }catch (Exception ex){
//             System.out.println("===Please check the next exception:===============");
//             throw ex;
//         }
//     }
//
//     //############################1111111#######################################
//     //1	Service	GetService(ListBucket)	对于做Get请求的服务，返回请求者拥有的所有Bucket，
//     // 其中“/”表示根目录。该API只对验证用户有效，匿名用户不能执行该操作。
//     public static void listBuckets(AmazonS3 ossClient){
//         List<Bucket> listBuckets = ossClient.listBuckets();
//         for (Bucket bucketInfo : listBuckets) {
//             System.out.println("listBuckets:"
//                     + "\t Name:" + bucketInfo.getName()
//                     + "\t CreationDate:" + bucketInfo.getCreationDate()
//                     + "\t Owner:"+ bucketInfo.getOwner());
//         }
//     }
//
//     //2	Service	Get Regions	获取资源池中的索引位置和数据位置列表
//     //该接口只能在对象存储网络使用，5.0的资源池无法使用
//     public static void getRegions(AmazonS3 ossClient){
//         CtyunGetRegionsResult region =  ossClient.ctyunGetRegions();
//
//         if(region != null ){
//             List<String> metadataRegions = region.getMetadataRegions();
//             List<String> dataRegions = region.getDataRegions();
//
//             if(metadataRegions!= null){
//                 for (String  metadataRegion : metadataRegions) {
//                     System.out.println("getRegions:"
//                             + "\t metadataRegion:" + metadataRegion);
//                 }
//             }
//
//             if(dataRegions!= null){
//                 for (String  dataRegion : region.getDataRegions()) {
//                     System.out.println("getRegions:"
//                             + "\t dataRegion:" + dataRegion);
//                 }
//             }
//         }
//     }
//
//     //3	1	Bucket	Put Bucket	创建一个新的bucket
//     //本方法只能在版本5的资源池上使用
//     public static void putBucket(AmazonS3 ossClient){
//         myBucketName = "bkt-hhhhtest2";
//         CreateBucketRequest request = new CreateBucketRequest(myBucketName);
//         request.setCannedAcl(CannedAccessControlList.Private);
//         Bucket bucketInfo = ossClient.createBucket(request);
//         System.out.println("puteBucket:"
//                 + "\t Name:" + bucketInfo.getName()
//                 + "\t CreationDate:" + bucketInfo.getCreationDate()
//                 + "\t Owner:"+ bucketInfo.getOwner());
//     }
//
//     public static void putBucket1(AmazonS3 ossClient){
//         myBucketName = "hhtest0422";
//         Bucket bucketInfo = ossClient.createBucket(myBucketName,"ChengDu","ShenYang");
//         System.out.println("putBucket:"
//                 + "\t Name:" + bucketInfo.getName()
//                 + "\t CreationDate:" + bucketInfo.getCreationDate()
//                 + "\t Owner:"+ bucketInfo.getOwner());
//     }
//
//     public static void putBucket2(AmazonS3 ossClient){
//         for(int i=0;i<1;i++) {
//             myBucketName = "yxxxytest-1436"+i;
//             Bucket bucketInfo = ossClient.createBucket(myBucketName);
//             System.out.println("putBucket:"
//                     + "\t Name:" + bucketInfo.getName()
//                     + "\t CreationDate:" + bucketInfo.getCreationDate()
//                     + "\t Owner:"+ bucketInfo.getOwner());
//         }
//     }
//
//
//     //3	1	Bucket	Put Bucket	创建一个新的bucket
//     //本方法只能在版本6的资源池上使用，并且需要getRegions获得可用的location
//     public static void putBucketToLocation(AmazonS3 ossClient,String bucketName){
//         String metaLocation = "beijing-hwl";
//         String dataLocation = "beijing-hwl";
//         //myBucketName = "csharpa122";
//         CreateBucketRequest request = new CreateBucketRequest(bucketName);
//         request.setCannedAcl(CannedAccessControlList.Private);
//         List<String> dataRegions = new ArrayList<>();
//         dataRegions.add(dataLocation);
//         CtyunBucketDataLocation ctyunBucketDataLocation = new CtyunBucketDataLocation().withDataRegions(dataRegions);
//
//         request.setMetadataLocation(metaLocation);
//         request.setDataLocation(ctyunBucketDataLocation);
//         try {
//             Bucket bucketInfo = ossClient.createBucket(request);
//
//             //Bucket bucketInfo = ossClient.createBucket(myBucketName,metaLocation,dataLocation);
//             //bucketInfo = ossClient.createBucket(request);
//             System.out.println("puteBucket:"
//                     + "\t Name:" + bucketInfo.getName()
//                     + "\t CreationDate:" + bucketInfo.getCreationDate()
//                     + "\t Owner:"+ bucketInfo.getOwner());
//         } catch (Exception e) {
//
//             System.out.println(e.toString());
//         }
//
//     }
//
//     public static void putBucketToLocation(AmazonS3 ossClient) {
//         putBucketToLocation(ossClient, myBucketName);
//     }
//     //3	1	Bucket	Put Bucket	创建一个新的bucket
//     //本方法只能在版本6的资源池上使用，并且需要getRegions获得可用的location
//     public static void putBucketToLocationWithAcl(AmazonS3 ossClient){
//         String metaLocation = "beijing-hwl";
//         String dataLocation = "beijing-hwl";
//         myBucketName = "csharpc";
//         List<String> dataRegions = new ArrayList<>();
//         dataRegions.add(dataLocation);
//         CtyunBucketDataLocation ctyunBucketDataLocation = new CtyunBucketDataLocation().withDataRegions(dataRegions);
//         CreateBucketRequest request = new CreateBucketRequest(myBucketName,metaLocation,ctyunBucketDataLocation);
//         request.setCannedAcl(CannedAccessControlList.PublicReadWrite);
//
//         Bucket bucketInfo = ossClient.createBucket(request);
//         System.out.println("puteBucket:"
//                 + "\t Name:" + bucketInfo.getName()
//                 + "\t CreationDate:" + bucketInfo.getCreationDate()
//                 + "\t Owner:"+ bucketInfo.getOwner());
//     }
//
//     //3	1	Bucket	Put Bucket	创建一个新的bucket
//     //本方法只能在版本6的资源池上使用，并且需要getRegions获得可用的location
//     public static void putBucketToMultiDataLocation(AmazonS3 ossClient){
//         myBucketName = "javatesta";
//         String metaLocation = "ZhengZhou";
//         String dataLocation1 = "ZhengZhou";
//         String dataLocation2 = "ShenYang";
//
//         List<String> dataRegions = new ArrayList<>();
//         dataRegions.add(dataLocation1);
//         dataRegions.add(dataLocation2);
//
//         CtyunBucketDataLocation dataLocation = new CtyunBucketDataLocation().withDataRegions(dataRegions);
//
//         dataLocation.setStragegy(CtyunBucketDataLocation.CtyunBucketDataScheduleStrategy.NotAllowed);
//
//         CreateBucketRequest createBucketRequest = new CreateBucketRequest(myBucketName,metaLocation,dataLocation);
//
//         Bucket bucketInfo = ossClient.createBucket(createBucketRequest);
//         System.out.println("puteBucket:"
//                 + "\t Name:" + bucketInfo.getName()
//                 + "\t CreationDate:" + bucketInfo.getCreationDate()
//                 + "\t Owner:"+ bucketInfo.getOwner());
//     }
//
//     //2	Bucket	Get Bucket location	获取bucket的索引位置和数据位置
//     //本方法只能在版本6的资源池上使用，
//     public static void getBucketLocation(AmazonS3 ossClient){
//         //myBucketName = "javatesta";
//         CtyunGetBucketLocationResult locationResult = ossClient.getBucketLocation(myBucketName);
//
//         System.out.println("getBucketLocation:"
//                 + "\t MetaRegion:" + locationResult.getMetaRegion()
//                 + "\t DataLocation:" + locationResult.getDataLocation().getDataRegions().toString()
//         );
//         CtyunGetBucketLocationResult locationResult2 = ossClient.getBucketLocation(dstBucketName);
//
//         System.out.println("getBucketLocation:"
//                 + "\t MetaRegion:" + locationResult2.getMetaRegion()
//                 + "\t DataLocation:" + locationResult2.getDataLocation().getDataRegions().toString()
//         );
//     }
//
//     //3	Bucket	Get bucket acl	获取bucket的ACL信息
//     public static void getBucketAcl(AmazonS3 ossClient){
//         AccessControlList list = ossClient.getBucketAcl(myBucketName);
//     }
//
//     //4	Bucket	GET Bucket (List Objects)	返回bucket中部分或者全部（最多1000）的object信息。
//     public static void listObjects(AmazonS3 ossClient){
//         ListObjectsRequest listObjectsRequest  = new ListObjectsRequest();
//         listObjectsRequest.setPrefix("doc/");
//         listObjectsRequest.setMarker("doc/F");
//         listObjectsRequest.setDelimiter("/");
//         listObjectsRequest.setMaxKeys(40);
//         listObjectsRequest.setBucketName("testphpa");
//         ObjectListing list = ossClient.listObjects(listObjectsRequest);
//     }
//
//     private static void listAndDelObjects(AmazonS3 ossClient,String bucket){
//         ListObjectsRequest listObjectsRequest  = new ListObjectsRequest();
//         String keyString;
//         //listObjectsRequest.setPrefix("doc/");
//         //listObjectsRequest.setMarker("doc/F");
//         //listObjectsRequest.setDelimiter("/");
//         //listObjectsRequest.setMaxKeys(40);
//         listObjectsRequest.setBucketName(bucket);
//         ObjectListing list = ossClient.listObjects(listObjectsRequest);
//         int sz= list.getObjectSummaries().size();
//         System.out.println("object count:"+sz);
//         for(int i=0;i<sz;i++) {
//             keyString= list.getObjectSummaries().get(i).getKey();
//             ossClient.deleteObject(bucket,keyString);
//             System.out.println("del object :"+bucket+":"+keyString);
//         }
//         while (true == list.isTruncated()) {
//
//             listObjectsRequest = new ListObjectsRequest()
//                     .withBucketName(bucket)
//                     .withMarker(list.getNextMarker())
//             ;
//             list = ossClient.listObjects(listObjectsRequest);
//             for(int i = 0; i < list.getObjectSummaries().size(); i++) {
//                 keyString= list.getObjectSummaries().get(i).getKey();
//                 ossClient.deleteObject(bucket, keyString);
//                 System.out.println("del object :"+bucket+":"+keyString);
//             }
//         }
//         ossClient.deleteBucket(bucket);
//     }
//
//     //5	Bucket	Delete bucket	执行删除bucket的操作
//     public static void deleteBucket(AmazonS3 ossClient){
//         ossClient.deleteBucket(myBucketName);
//     }
//
//     //6	Bucket	Put Bucket Policy	进行添加或修改policy的操作。如果bucket已经存在了Policy，此操作会替换原有Policy。
//     // 只有bucket的owner才能执行此操作，否则会返回403 AccessDenied错误。
//     public static void setBucketPolicy(AmazonS3 ossClient){
//         String buffer = "   {   "
//                 +"         'Version':'2012-10-17',   "
//                 +"         'Id':'http referer policy example',   "
//                 +"                'Statement':[   "
//                 +"              {   "
//                 +"               'Sid':'Allow get requests referred by www.mysite.com ',   "
//                 +"                   'Effect':'Allow',   "
//                 +"                    'Principal':{   "
//                 +"                          'AWS':[   "
//                 +"                           '*'   "
//                 +"                                ]   "
//                 +"                      },   "
//                 +"                  'Action':'s3:*',   "
//                 +"                  'Resource':'arn:aws:s3:::" + myBucketName +"/*',   "
//                 +"                  'Condition':{   "
//                 +"                      'StringLike':{   "
//                 +"                          'aws:Referer':[   "
//                 +"                              'http://www.mysite.com/*'  "
//                 +"                          ]  "
//                 +"                   }  "
//                 +"              }  "
//                 +"           }  "
//                 +"       ]  "
//                 +"      }  " ;
//
//         ossClient.setBucketPolicy(myBucketName,buffer);
//     }
//
//     //7	Bucket	Get Bucket Policy	获得指定bucket的policy。只有bucket的owner才能执行此操作，
//     // 否则会返回403 AccessDenied错误。如果bucket没有policy，返回404，NoSuchPolicy错误。
//     public static void getBucketPolicy(AmazonS3 ossClient){
//         ossClient.getBucketPolicy(myBucketName);
//     }
//
//     //8	Bucket	Delete bucket Policy	删除指定bucket的policy。只有bucket的owner才能执行此操作，
//     // 否则会返回403 AccessDenied错误。如果bucket没有policy，返回204 NoContent。
//     public static void deleteBucketPolicy(AmazonS3 ossClient){
//         ossClient.deleteBucketPolicy(myBucketName);
//     }
//
//     //9	Bucket	Put Bucket WebSite	设置website配置。如果bucket已经存在了website，此操作会替换原有website。
//     // 只有bucket的owner才能执行此操作，否则会返回403 AccessDenied错误。
//     public static void putBucketWebsite(AmazonS3 ossClient){
//         BucketWebsiteConfiguration configuration = new BucketWebsiteConfiguration();
//         configuration.setIndexDocumentSuffix("index.html");
//         configuration.setErrorDocument("error.html");
//         ossClient.setBucketWebsiteConfiguration(myBucketName,configuration);
//     }
//
//     //10	Bucket	Get Bucket WebSite	获得指定bucket的website。
//     // 只有bucket的owner才能执行此操作，否则会返回403 AccessDenied错误。
//     public static void getBucketWebsite(AmazonS3 ossClient){
//         ossClient.getBucketWebsiteConfiguration(myBucketName);
//     }
//
//     //11	Bucket	Delete bucket WebSite	删除指定bucket的website。只有bucket的owner才能执行此操作，
//     // 否则会返回403 AccessDenied错误。如果bucket没有website，返回200 OK
//     public static void deleteBucketWebsite(AmazonS3 ossClient){
//         ossClient.deleteBucketWebsiteConfiguration(myBucketName);
//     }
//
//     //12	Bucket	List Multipart Uploads	列出所有已经通过Initiate Multipart Upload请求初始化，但未完成或未终止的分片上传过程。
//     public static void listMultipartUploads(AmazonS3 ossClient){
//         // 'delimiter' => '/',
//         //        'max-uploads' => 100,
//         //        // 'key-marker' => '',
//         //        'prefix' => '',
//         //        'upload-id-marker' => ''
//         ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(myBucketName);
//         listMultipartUploadsRequest.setDelimiter("/");
//         listMultipartUploadsRequest.setMaxUploads(100);
//         listMultipartUploadsRequest.setPrefix("");
//         ossClient.listMultipartUploads(listMultipartUploadsRequest);
//     }
//
//     //13	Bucket	Put Bucket Logging
//     public static void putBucketLogging(AmazonS3 ossClient){
//         BucketLoggingConfiguration loggingConfiguration = new BucketLoggingConfiguration();
//
//         loggingConfiguration.setLogFilePrefix("prefix-1");
//         loggingConfiguration.setDestinationBucketName(myBucketName);
//
//         SetBucketLoggingConfigurationRequest setBucketLoggingConfigurationRequest =
//                 new SetBucketLoggingConfigurationRequest(myBucketName,loggingConfiguration);
//
//
//         ossClient.setBucketLoggingConfiguration(setBucketLoggingConfigurationRequest);
//     }
//     //14	Bucket	Get Bucket Logging
//     public static void getBucketLogging(AmazonS3 ossClient){
//         BucketLoggingConfiguration logging = ossClient.getBucketLoggingConfiguration(myBucketName);
//     }
//
//     //15 Bucket	Head Bucket
//     public static void doesBucketExist(AmazonS3 ossClient){
//         ossClient.doesBucketExist(myBucketName);
//     }
//
//     // head bucket
//     public static void headBucket(AmazonS3 ossClient){
//         ossClient.headBucket(myBucketName);
//     }
//
//     public static void headBucket_noExist(AmazonS3 ossClient){
//         try {
//             HeadBucketRequest request = new HeadBucketRequest("no-existbucket");
//             ossClient.headBucket(request);
//         } catch (AmazonS3Exception e) {
//             System.out.println(e.toString());
//         }
//     }
//
//     //16 Bucket	Put Bucket Lifecycle	使用对象到期功能来指定bucket中对象的生命周期
//     public static void putBucketLifecycle(AmazonS3 ossClient){
//         myBucketName = "javatest6";
//         BucketLifecycleConfiguration bucketLifecycleConfiguration = new BucketLifecycleConfiguration();
//
//         List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<>();
//         BucketLifecycleConfiguration.Rule rule1 = new BucketLifecycleConfiguration.Rule();
//         rule1.setId("rule1");
//         rule1.setPrefix("test");
//         rule1.setStatus("Enabled");
//         rule1.setExpirationInDays(30);
//         rules.add(rule1);
//
//         bucketLifecycleConfiguration.setRules(rules);
//
//         ossClient.setBucketLifecycleConfiguration(myBucketName,bucketLifecycleConfiguration);
//     }
//
//     //17 Bucket	Get Bucket Lifecycle	返回配置的bucket生命周期
//     public static void getBucketLifecycle(AmazonS3 ossClient){
//         ossClient.getBucketLifecycleConfiguration(myBucketName);
//     }
//
//     //18 Bucket	Delete Bucket Lifecycle	此接口用于删除配置的bucket生命周期，OOS将会删除指定bucket的所有生命周期配置规则
//     public static void deleteBucketLifecycle(AmazonS3 ossClient){
//         ossClient.deleteBucketLifecycleConfiguration(myBucketName);
//     }
//
//     //19	Bucket	Put Bucket accelerate	在PUT操作的url中加上accelerate，可以进行添加或修改CDN IP白名单的操作
//     public static void putAccelerate(AmazonS3 ossClient){
//         CtyunAccelerateMetadata accelerate = new CtyunAccelerateMetadata();
//
//         List<String> ipWhiteList = new ArrayList<String>();
//         ipWhiteList.add("36.111.88.0/24");
//         ipWhiteList.add("114.80.1.136");
//         accelerate.setStatus("Enabled");
//         accelerate.setIpWhiteList(ipWhiteList);
//
//         CtyunAccelerateConfiguration accelerateConfiguration = new CtyunAccelerateConfiguration();
//         accelerateConfiguration.setAccelerate(accelerate);
//
//         CtyunSetAccelerateConfigurationRequest accelerateRequest = new CtyunSetAccelerateConfigurationRequest(
//                 myBucketName,accelerateConfiguration);
//
//         ossClient.ctyunSetAccelerate(accelerateRequest);
//     }
//
//     //20	Bucket	Get Bucket accelerate	在GET操作的url中加上accelerate，可以获得指定bucket的cdn配置信息
//     public static void getAccelerate(AmazonS3 ossClient){
//         CtyunAccelerateConfiguration accelerate = ossClient.ctyunGetAccelerate(myBucketName);
//     }
//
//
//     //21	Bucket	PUT Bucket cors	通过 CORS ，客户可以构建丰富的客户端 Web 应用程序，同时可以选择性地允许跨域访问OOS 资源
//     public static void putBucketCors(AmazonS3 ossClient){
//         BucketCrossOriginConfiguration bucketCrossOriginConfiguration = new BucketCrossOriginConfiguration();
//
//         CORSRule rule = new CORSRule();
//
//         List<CORSRule.AllowedMethods> allowedMethods = new ArrayList<CORSRule.AllowedMethods>();
//         allowedMethods.add(CORSRule.AllowedMethods.GET);
//         allowedMethods.add(CORSRule.AllowedMethods.POST);
//
//         List<String> allowedOrigins = new ArrayList();
//         allowedOrigins.add("a");
//         allowedOrigins.add("b");
//
//         int maxAgeSeconds = 1000;
//
//         List<String> exposedHeaders = new ArrayList();
//         List<String> allowedHeaders = new ArrayList();
//
//         exposedHeaders.add("e1");
//         exposedHeaders.add("e2");
//
//         allowedHeaders.add("a1");
//         allowedHeaders.add("a2");
//
//         rule.setId("myfirstRuleId");
//         rule.setAllowedMethods(allowedMethods);
//         rule.setAllowedOrigins(allowedOrigins);
//         rule.setExposedHeaders(exposedHeaders);
//         rule.setAllowedHeaders(allowedHeaders);
//
//         List<CORSRule> rules = new ArrayList<CORSRule>();
//         rules.add(rule);
//
//         bucketCrossOriginConfiguration.setRules(rules);
//
//         CtyunAccelerateConfiguration accelerateConfiguration;
//
//         ossClient.setBucketCrossOriginConfiguration(myBucketName,bucketCrossOriginConfiguration);
//     }
//
//     //22	Bucket	GET Bucket cors	返回bucket的跨域配置信息
//     public static void getBucketCors(AmazonS3 ossClient){
//         BucketCrossOriginConfiguration cors = ossClient.getBucketCrossOriginConfiguration(myBucketName);
//     }
//
//     //23	Bucket	DELETE Bucket cors	删除bucket的跨域配置信息
//     public static void deleteBucketCors(AmazonS3 ossClient){
//         ossClient.deleteBucketCrossOriginConfiguration(myBucketName);
//     }
//
//     //24	PUT Bucket Trigger	在PUT操作的url中加上trigger
//     public static void putBucketTrigger(AmazonS3 ossClient){
//         CtyunTriggerMetadata triggerMetadata = new CtyunTriggerMetadata();
//         triggerMetadata.setTriggerName("theTriggerNameForTwoRemoteSite");
//         List<CtyunRemoteSite> remoteSites = new ArrayList<>();
//         CtyunRemoteSite remoteSite1 = new CtyunRemoteSite();
//
//         remoteSite1.setRemoteAK("your remoteAK1");
//         remoteSite1.setRemoteSK("your remoteSK1");
//         remoteSite1.setRemoteBucketName("bucket1");
//         remoteSite1.setRemoteEndPoint("http://oos-js.ctyunapi.cn");
//         remoteSite1.setReplicaMode("EC_3_0");
//
//         remoteSites.add(remoteSite1);
//
//         CtyunRemoteSite remoteSite2 = new CtyunRemoteSite();
//         remoteSite2.setRemoteAK("your remoteAK2");
//         remoteSite2.setRemoteSK("your remoteSK2");
//         remoteSite2.setRemoteBucketName("bucket2");
//         remoteSite2.setRemoteEndPoint("http://oos-nm2.ctyunapi.cn");
//         remoteSite2.setReplicaMode("EC_3_0");
//
//         remoteSites.add(remoteSite2);
//
//         triggerMetadata.setDefault(true);
//         triggerMetadata.setRemoteSites(remoteSites);
//
//         List<CtyunTriggerMetadata> triggers = new ArrayList<>();
//         triggers.add(triggerMetadata);
//
//         CtyunBucketTriggerConfiguration triggerConfiguration = new CtyunBucketTriggerConfiguration();
//         triggerConfiguration.setTriggers(triggers);
//
//         CtyunSetBucketTriggerConfigurationRequest triggerConfigurationRequest =
//                 new CtyunSetBucketTriggerConfigurationRequest(myBucketName,triggerConfiguration);
//
//         ossClient.ctyunSetBucketTrigger(triggerConfigurationRequest);
//     }
//
//     //25	Bucket	 GET Bucket Trigger	查询某bucket中配置的所有trigger
//     public static void getBucketTrigger(AmazonS3 ossClient){
//         ossClient.ctyunDeleteBucketTrigger(myBucketName,"theTriggerNameForTwoRemoteSite");
//     }
//
//     //26	Bucket	 Delete Bucket Trigger	删除某bucket中的指定trigger
//     public static void deleteBucketTrigger(AmazonS3 ossClient){
//         ossClient.ctyunGetBucketTrigger(myBucketName);
//     }
//
//     //############################Object#######################################
//     //29	Object	Put Object
//     //该例子可以在5和对象存储网络使用
//     public static void putObject(AmazonS3 ossClient){
//         System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "false");
//         myBucketName = "bkt-hhhhtest";
//         String key = "lb-org.jpg";
//         PutObjectResult  result ;
//         File testFile = new File("D:\\tmp\\lb-org.jpg");
//         PutObjectRequest request = new PutObjectRequest(myBucketName,key,testFile);
//         request.setStorageClass(StorageClass.ReducedRedundancy);
//         result = ossClient.putObject(request);
//         System.out.println("put object:" + key + ",md5: "+ result.getContentMd5());
//     }
//
//     //29	Object	Put Object to Location
//     //该例子只以在对象存储网络使用
//     public static void putObjectToLocation(AmazonS3 ossClient){
//         String objectInBucketKey = "开发者文档.xml";
//         File testFile = new File("D:\\tmp\\1.txt");
//         PutObjectResult  result;
//         PutObjectRequest request = new PutObjectRequest(myBucketName,objectInBucketKey2,testFile);
// /*
//         ObjectMetadata metadata = new ObjectMetadata();
//
//         CtyunBucketDataLocation dataLocation = new CtyunBucketDataLocation();
//         dataLocation.setType(CtyunBucketDataLocation.CtyunBucketDataType.Specified);
//
//         List<String> dataRegions = new ArrayList<String>();
//         dataRegions.add("QingDao");
//         dataRegions.add("ShenZhen");
//
//         dataLocation.setDataRegions(dataRegions);
//
//         metadata.setDataLocation(dataLocation);
//
//         request.setMetadata(metadata);
//
//  */
//         result = ossClient.putObject(request);
//         System.out.println("put object:" + objectInBucketKey2 + "md5:"+ result.getContentMd5());
//     }
//
//     //30	Get Object
//     public static void getObject(AmazonS3 ossClient) throws IOException{
//         String localFilePath = "D:\\TMP\\lb-org-down.jpg";
//         // String objectInBucketKey = "A2.txt";
//         //myBucketName = "csharp19";
//         String objectInBucketKey = "lb-org.jpg";
//
//         GetObjectRequest request = new GetObjectRequest(myBucketName,objectInBucketKey);
//         //request.setLimit("2048");
//         //request.setLimitrate("2048");
//         //request.setRange(0,100);  //Start-End  取部分内容 End不能大于文件长度
//         S3Object s3Object = ossClient.getObject(request);
//
//
//         //S3Object s3Object = ossClient.getObject(myBucketName,objectInBucketKey);  //取全部
//
//         //InputStream input = new ByteArrayInputStream(object.getObjectContent());
//
//         //        ResponseHeaderOverrides headerOverrides = new ResponseHeaderOverrides();
//         //        headerOverrides.setContentType("");
//         //        request.setResponseHeaders(headerOverrides);
//         S3ObjectInputStream input = s3Object.getObjectContent();
//         FileOutputStream fos = null;
//         try {
//             int bufferSize = 10 * 1024;
//             byte [] bytes = new byte[bufferSize];
//             File file = new File(localFilePath);
//             fos = new FileOutputStream(file);
//
//             byte[] buffer = new byte[bufferSize];
//             int bytesRead= -1;
//             while ((bytesRead = input.read(buffer)) > -1) {
//                 fos.write(buffer, 0, bytesRead);
//             }
//
//             fos.flush();
//             //input.reset();
//         }
//         catch (IOException e) {
//             try {
//                 input.abort();
//             } catch (IOException abortException) {}
//         }
//         finally {
//             if (fos != null)
//                 fos.close();
//             if(input != null)
//                 input.close();
//         }
//
//         //如果是S6，查看getObjectMetadata
//         if(!DomainConfig.isS5Endpoint(TestConfig.OOS_ENDPOINT)){
//             s3Object.getObjectMetadata();
//         }
//     }
//
//     //31	Delete Object
//     public static void deleteObject(AmazonS3 ossClient){
//         String objectInBucketKey = "lb.jpg";
//         ossClient.deleteObject(myBucketName,objectInBucketKey);
//     }
//
//     //32 PUT Object - Copy
//     public static void copyObject(AmazonS3 ossClient){
//         String objectInBucketKey1 = "src.zip";
//         String objectInBucketKey2 = "srccopy.zip";
//         CopyObjectRequest request = new CopyObjectRequest(
//                 myBucketName,objectInBucketKey1,myBucketName,objectInBucketKey2);
//         CopyObjectResult result = ossClient.copyObject(request);
//         System.out.println(result.toString());
//     }
//
//     //32 PUT Object - Copy to location
//     //该例子只以在对象存储网络使用
//     public static void copyObjectToLocation(AmazonS3 ossClient){
//         String objectInBucketKey1 = "objectInBucketKey1";
//         String objectInBucketKey2 = "objectInBucketKey2";
//         CopyObjectRequest request = new CopyObjectRequest(
//                 myBucketName,objectInBucketKey1,myBucketName,objectInBucketKey2);
//
//         ObjectMetadata metadata = new ObjectMetadata();
//
//         CtyunBucketDataLocation dataLocation = new CtyunBucketDataLocation();
//         dataLocation.setType(CtyunBucketDataLocation.CtyunBucketDataType.Specified);
//
//         List<String> dataRegions = new ArrayList<String>();
//         dataRegions.add("ShenZhen");
//         dataRegions.add("QingDao");
//
//         dataLocation.setDataRegions(dataRegions);
//
//         metadata.setDataLocation(dataLocation);
//
//         request.setNewObjectMetadata(metadata);
//
//         ossClient.copyObject(request);
//     }
//
//     //33 Initial Multipart Upload	本接口初始化一个分片上传（Multipart Upload）操作，
//     // 并返回一个上传ID，此ID用来将此次分片上传操作中上传的所有片段合并成一个对象。
//     // 用户在执行每一次子上传请求（见Upload Part）时都应该指定该ID。用户也可以在表示整个分片上传
//     // 完成的最后一个请求中指定该ID。
//     public static String initiateMultipartUpload(AmazonS3 ossClient){
//         //String objectInBucketKey2 = "httpd-2.4.38.tar.bz2";
//
//         InitiateMultipartUploadRequest request =
//                 new InitiateMultipartUploadRequest(myBucketName,dstObjectName);
//
//         InitiateMultipartUploadResult res = ossClient.initiateMultipartUpload(request);
//         String uploadID = res.getUploadId();
//
//         System.out.println("=========uploadID:\t :" + uploadID);
//         return uploadID;
//     }
//
//     //33 Initial Multipart Upload	本接口初始化一个分片上传（Multipart Upload）操作，
//     // 并返回一个上传ID，此ID用来将此次分片上传操作中上传的所有片段合并成一个对象。
//     // 用户在执行每一次子上传请求（见Upload Part）时都应该指定该ID。用户也可以在表示整个分片上传
//     // 完成的最后一个请求中指定该ID。
//     //该例子只以在对象存储网络使用,而且必须先通过getRegions查到可用的dataRegions
//     public static void initiateMultipartUploadToLocation(AmazonS3 ossClient){
//         String objectInBucketKey2 = "objectInBucketKey2";
//
//         ObjectMetadata metadata = new ObjectMetadata();
//
//         CtyunBucketDataLocation dataLocation = new CtyunBucketDataLocation();
//         dataLocation.setType(CtyunBucketDataLocation.CtyunBucketDataType.Specified);
//
//         List<String> dataRegions = new ArrayList<String>();
//         dataRegions.add("ShenZhen");
//         dataRegions.add("QingDao");
//
//         dataLocation.setDataRegions(dataRegions);
//
//         metadata.setDataLocation(dataLocation);
//
//         InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(myBucketName,objectInBucketKey2, metadata);
//         InitiateMultipartUploadResult res = ossClient.initiateMultipartUpload(request);
//         String uploadID = res.getUploadId();
//
//         System.out.println("=========uploadID:\t :" + uploadID);
//     }
//
//     //34 Upload Part	在上传任何一个分片之前，必须执行Initial Multipart Upload操作来初始化分片上传操作，初始化成功后，
//     //OOS会返回一个上传ID，这是一个唯一的标识，用户必须在调用Upload Part接口时加入该ID
//     public static String uploadPart(AmazonS3 ossClient,String uploadId){
//         //String objectInBucketKey2 = "httpd-2.4.38.tar.bz2";
//
//         UploadPartRequest request = new UploadPartRequest().withUploadId(uploadId);
//
//         //php7.zip
//         File testFile = new File("D:\\tmp\\test.zip");
//         request.setFile(testFile);
//         request.setBucketName(myBucketName);
//         request.setKey(objectInBucketKey2);
//         request.setPartNumber(1);
//         request.setPartSize(testFile.length());
//
//         UploadPartResult res = ossClient.uploadPart(request);
//
//         String eTag = res.getETag();
//
//         System.out.println("=========eTag:\t :" + eTag);
//         return eTag;
//     }
//
//     //35 Complete Multipart Upload	该接口通过合并之前的上传片段来完成一次分片上传过程。
//     public static void completeMultipartUpload(AmazonS3 ossClient){
//         String objectInBucketKey2 = "objectInBucketKey2";
//
//         List<PartETag> partETags = new ArrayList<PartETag>();
//         partETags.add(new PartETag(1,"706010df87ac70109e9aec2048398440"));
//         partETags.add(new PartETag(2,"1f899f12654368ed5cce3ff99f026e49"));
//
//
//         CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(
//                 myBucketName,objectInBucketKey2,"1552564842600683248",partETags);
//
//         CompleteMultipartUploadResult result = ossClient.completeMultipartUpload(request);
//     }
//
//     public static void completeMultipartUpload(AmazonS3 ossClient,String uploadID,String etag){
//         //String objectInBucketKey2 = "httpd-2.4.38.tar.bz2";
//
//         List<PartETag> partETags = new ArrayList<PartETag>();
//         partETags.add(new PartETag(1,etag));
//
//         CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(
//                 myBucketName,objectInBucketKey2,uploadID,partETags);
//
//         CompleteMultipartUploadResult result = ossClient.completeMultipartUpload(request);
//     }
//
//     //36 Abort Multipart Upload	该接口用于终止一次分片上传操作。
//     public static void abortMultipartUpload(AmazonS3 ossClient){
//         String objectInBucketKey2 = "objectInBucketKey2";
//
//         AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(
//                 myBucketName,objectInBucketKey2,"1552564842600683248");
//
//         ossClient.abortMultipartUpload(request);
//     }
//
//     //36 Abort Multipart Upload 该接口用于终止一次分片上传操作。
//     public static void abortMultipartUpload(AmazonS3 ossClient,String uploadId){
//         //String objectInBucketKey2 = "objectInBucketKey2";
//
//         AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(
//                 myBucketName,objectInBucketKey2,uploadId);
//
//         ossClient.abortMultipartUpload(request);
//     }
//
//     //37 List Part	列出一次分片上传过程中已经上传完成的所有片段
//     public static void listParts(AmazonS3 ossClient){
//         String objectInBucketKey2 = "objectInBucketKey2";
//
//         ListPartsRequest request = new ListPartsRequest(
//                 myBucketName,objectInBucketKey2,"1552564842600683248");
//
//
//         PartListing result = ossClient.listParts(request);
//         int size = result.getParts().size();
//
//         System.out.println("=========size:\t :" + size);
//     }
//
//     //37 List Part 列出一次分片上传过程中已经上传完成的所有片段
//     public static void listParts(AmazonS3 ossClient,String uploadId){
//         //String objectInBucketKey2 = "objectInBucketKey2";
//
//         ListPartsRequest request = new ListPartsRequest(
//                 myBucketName,objectInBucketKey2,uploadId);
//
//
//         PartListing result = ossClient.listParts(request);
//         int size = result.getParts().size();
//
//         System.out.println("=========size:\t :" + size);
//     }
//
//     //38 Copy Part	可以将已经存在的object作为分段上传的片段，拷贝生成一个新的片段
//     public static void copyPart(AmazonS3 ossClient,String uploadId){
//         CopyPartRequest request = new CopyPartRequest();
//         request.setSourceBucketName(myBucketName);
//         request.setSourceKey(objectInBucketKey2);
//         request.setDestinationBucketName(dstBucketName);
//         request.setDestinationKey(dstObjectName);
//
//         //请求头格式为x-amz-copy-source-range:bytes=first-last
//         //默认无需设置,设置时必须同时设置,下例为x-amz-copy-source-range:bytes=0-100
//         //request.setFirstByte(0L);
//         //request.setLastByte(100L);
//
//         request.setPartNumber(1);
//
//         request.setUploadId(uploadId);
//
//         CopyPartResult result = ossClient.copyPart(request);
//     }
//
//     //40 Delete Multiple Objects	批量删除Object功能支持用一个HTTP请求删除一个bucket中的多个object。
//     public static void deleteObjects(AmazonS3 ossClient){
//         myBucketName = "csharp19";
//         String objectInBucketKey1 = "iloveyou.vbs";
//         String objectInBucketKey2 = "pom.xml";
//         String objectInBucketKey3 = "开发者文档.xml";
//         String objectInBucketKey4 = "v4.txt";
//
//         DeleteObjectsRequest request = new DeleteObjectsRequest(myBucketName);
//         DeleteObjectsRequest.KeyVersion key1 = new DeleteObjectsRequest.KeyVersion(objectInBucketKey1,null);
//         DeleteObjectsRequest.KeyVersion key2 = new DeleteObjectsRequest.KeyVersion(objectInBucketKey2,null);
//         DeleteObjectsRequest.KeyVersion key3 = new DeleteObjectsRequest.KeyVersion(objectInBucketKey3,null);
//         DeleteObjectsRequest.KeyVersion key4 = new DeleteObjectsRequest.KeyVersion(objectInBucketKey4,null);
//
//         List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<DeleteObjectsRequest.KeyVersion>();
//         keys.add(key1);
//         keys.add(key2);
//         keys.add(key3);
//         keys.add(key4);
//         request.withKeys(keys);
//
//         DeleteObjectsResult result = ossClient.deleteObjects(request);
//
//     }
//
//     //44 生成共享链接	对于私有或只读Bucket，可以通过生成Object的共享链接的方式，
//     //将Object分享给其他人，同时可以在链接中设置限速以对下载速度进行控制。
//     public static void generatePresignedUrl(AmazonS3 ossClient){
//         String bucketName = myBucketName;
//         String key = "lb-org.jpg" ;
//         //String uploadFile = "D:\\ZDX_DOC_DEV_SVN\\001-产品需求文档\\用户手册\\开发者文档\\OOS C SDK开发者指南-V6.pdf";
//
//         //        GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(
//         //                "csharp19","iloveyou.vbs");
//         GeneratePresignedUrlRequest shareUrlRequest = new GeneratePresignedUrlRequest(
//                 bucketName, key);
//         //shareUrlRequest.addRequestParameter("uploads", "");
//         //shareUrlRequest.setMethod(HttpMethod.POST);
//         //2019/11/20
//         java.util.Date expire = new java.util.Date(120,3,25);
//         shareUrlRequest.setExpiration(expire);
//
//
//         //shareUrlRequest.setSubResource(subResource);
//         URL url1 = ossClient.generatePresignedUrl(shareUrlRequest);
//         System.out.println(url1.toString());
//
//
//         //2019/09/10
//         //        java.util.Date expireDate = new java.util.Date(119,9,18);
//         //
//         //        request.setExpiration(expireDate);
//         //        request.addRequestParameter("x-amz-limitrate", "1024");
//         //        System.out.println("\n Time:" + expireDate.getTime());
//         //
//         //        URL url = ossClient.generatePresignedUrl(request);
//         //        System.out.println("\n url:" +url.toString());
//     }
//
//     //用sts 生成预签名url
//     public static void test_generatePresignedUrlSts(){
//         ClientConfiguration cc = new ClientConfiguration();
//         cc.setMaxErrorRetry(0);
//         cc.setConnectionTimeout(0);
//         cc.setProtocol(Protocol.HTTPS);
//
//         System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY,"true");
//         //System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "false");
//
//         AmazonIdentityManagementClient stsClient = new AmazonIdentityManagementClient(new AWSCredentials() {
//
//             @Override
//             public String getAWSAccessKeyId() {
//                 return TestConfig.OOS_ACCESS_ID_hwl;
//             }
//
//             @Override
//             public String getAWSSecretKey() {
//                 return TestConfig.OOS_ACCESS_KEY_hwl;
//             }
//         }, cc);
//         stsClient.setEndpoint(TestConfig.OOS_ENDPOINT_ACCESS_hwl);
//
//         GetSessionTokenRequest request = new GetSessionTokenRequest();
//         request.setDurationSeconds(7200);// 过期时间，单位秒
//         GetSessionTokenResult sessionTokenResult = stsClient.getSessionToken(request);
//         Credentials sessionCredentials = sessionTokenResult.getCredentials();
//         BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
//                 sessionCredentials.getAccessKeyId(), sessionCredentials.getSecretAccessKey(),
//                 sessionCredentials.getSessionToken());
//         AmazonS3 s3Client = new AmazonS3Client(basicSessionCredentials);
//         s3Client.setEndpoint(TestConfig.OOS_ENDPOINT_hwl);
//         String bucketName = "zztest0430";
//         String key = "lb.jpg";
//         java.util.Date expire = new java.util.Date(120, 4, 1);
//         URL url1 = s3Client.generatePresignedUrlSts(bucketName, key, expire);
//         System.out.println(url1.toString());
//
//     }
//
//     public static void generatePresignedUrlForListPartV2(AmazonS3 ossClient){
//         String bucketName = "javatest6";
//         String key = "OOS开发者文档-v6 - 副本.pdf" ;
//         //String key = null;
//         System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "false");
//         GeneratePresignedUrlRequest shareUrlRequest = new GeneratePresignedUrlRequest(
//                 bucketName, key);
//
//         //shareUrlRequest.addRequestParameter("acl", null);
//         shareUrlRequest.addRequestParameter("uploadId", "1111111");
//         //shareUrlRequest.setMethod(HttpMethod.POST);
//         //2019/11/20
//         java.util.Date expire = new java.util.Date(119,11,20);
//         shareUrlRequest.setExpiration(expire);
//
//         URL url1 = ossClient.generatePresignedUrl(shareUrlRequest);
//         System.out.println(url1.toString());
//     }
//
//     public static void generatePresignedUrlForObject(AmazonS3 ossClient){
//         String bucketName = "javatest6";
//         String key = "OOS开发者文档-v6 - 副本.pdf" ;
//         //String key = null;
//         System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "false");
//         GeneratePresignedUrlRequest shareUrlRequest = new GeneratePresignedUrlRequest(
//                 bucketName, key);
//
//
//         //shareUrlRequest.setMethod(HttpMethod.POST);
//         //2019/12/22
//         java.util.Date expire = new java.util.Date(119,11,22);
//         shareUrlRequest.setExpiration(expire);
//
//         URL url1 = ossClient.generatePresignedUrl(shareUrlRequest);
//         System.out.println(url1.toString());
//     }
//
//     public static String generatePresignedUrlForInitailPart(AmazonS3 ossClient){
//         GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(
//                 "testphpa", "object.php");
//         request.addRequestParameter("uploads", "");
//
//         request.setMethod(HttpMethod.POST);
//         java.util.Date expire = new java.util.Date(119,8,11);
//         request.setExpiration(expire);
//         request.addRequestParameter("x-amz-limitrate", "1024");
//         request.addRequestParameter("x-amz-copy-source", "abc");
//         URL url1 = ossClient.generatePresignedUrl(request);
//         System.out.println(url1.toString());
//
//         return url1.toString();
//     }
//
//     public static void initailPart(AmazonS3 ossClient) throws Exception {
//         String urlStr = generatePresignedUrlForInitailPart(ossClient);
//         URL url = new URL(urlStr);
//     }
//
//     //45 HEAD Object	Head 操作用于获取对象的元数据信息，而不返回数据本身。
//     public static void headObject(AmazonS3 ossClient){
//         String objectInBucketKey1 = "A2.txt";
//
//         ObjectMetadata metadata = ossClient.getObjectMetadata(myBucketName,objectInBucketKey1);
//     }
//     //###########################Keys##########################################
//
//
//     //###########################Keys##########################################
//     //1	Key	CreateAccessKey	创建一对普通的AccessKey和SecretKey，默认的状态是Active
//     public static void createAccessKey(AmazonS3 ossClient){
//         CreateAccessKeyResult result = ossClient.ctyunCreateAccessKey();
//         System.out.println(result.getAccessKey());
//     }
//
//     //2	Key	DeleteAccessKey	删除一对普通的AccessKey和SecretKey
//     public static void deleteAccessKey(AmazonS3 ossClient){
//         DeleteAccessKeyRequest request = new DeleteAccessKeyRequest();
//         request.setAccessKeyId("eb2a339c9aa8bdb3a575");
//         ossClient.ctyunDeleteAccessKey(request);
//     }
//
//     //3	Key	UpdateAccessKey	更新普通的AccessKey的状态，或将普通key设置成为主key，反之亦然
//     public static void updateAccessKey(AmazonS3 ossClient){
//         UpdateAccessKeyRequest updateAccessKeyRequest = new UpdateAccessKeyRequest();
//         updateAccessKeyRequest.setAccessKeyId("8b3d7349861aa7d52549");
//         updateAccessKeyRequest.setStatus("Active");
//         updateAccessKeyRequest.setCtyunIsPrimary("True");
//         ossClient.ctyunUpdateAccessKey(updateAccessKeyRequest);
//     }
//
//     //4	Key	ListAccessKey	列出账号下的主key和普通key
//     public static void listAccessKey(AmazonS3 ossClient){
//         ListAccessKeysRequest listAccessKeysRequest = new ListAccessKeysRequest();
//         listAccessKeysRequest.setMaxItems(50);
//
//         ListAccessKeysResult result = ossClient.ctyunListAccessKeys(listAccessKeysRequest);
//     }
//
//
//     //5	GetSessionToken	STS 临时授权访问
//     public static void getSessionToken(AWSSecurityTokenServiceClient ossClient){
//         GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
//         getSessionTokenRequest.setDurationSeconds(30*60);
//         GetSessionTokenResult result = ossClient.getSessionToken(getSessionTokenRequest);
//         result.getCredentials().getAccessKeyId();
//         result.getCredentials().getSecretAccessKey();
//
//     }
//
//     //4.3.15 断点续传
//     public static void multiUpload(AmazonS3 ossClient) {
//         try {
//             String bucketName = "bkt-hhhhtest";;
//             String key = "Python 开发者指南-V6-PD04.pdf" ;
//             String uploadFile = "D:\\tmp\\2.txt";
//
//             // 通过UploadFileRequest设置多个参数
//             UploadFileRequest request = new UploadFileRequest(bucketName, key);
//
//             // 上传的本地文件
//             request.setUploadFile(uploadFile);
//
//             // 分片上传并发线程数，默认为1，最多为1000
//             request.setTaskNum(2);
//
//             // 每个分片的大小，默认5MB，若partSize小于5MB，除了最后一个分片以外，会将partSize调整至5MB
//             request.setPartSize(5 * 1024 * 1024);
//
//             // 开启断点续传功能，默认关闭
//             request.setEnableCheckpoint(true);
//             // 记录本地分片上传结果的文件。开启断点续传功能时需要设置此参数，上传过程中的进度信息会保存在该文件中，如果某一分片上传失败，再次上传时会根据文件中记录的点继续上传。
//             // 上传完成后，该文件会被删除。默认与待上传的本地文件同目录，为uploadFile.ucp
//             // request.setCheckpointFile("<yourCheckpointFile>");
//             MultipleUpload multiUpload = new MultipleUpload(request, ossClient);
//
//             // 断点续传上传
//             CompleteMultipartUploadResult result = multiUpload.upload();
//             //System.out.println("location:  "+result.getLocation());
//             System.out.println("Upload complete. Upload object name:" + result.getKey());
//         } catch (AmazonServiceException ase) {
//             System.out.println("Caught an AmazonServiceException, which means your request made it " + "to OOS, but was rejected with an error response for some reason.");
//             System.out.println("Error Message:    " + ase.getMessage());
//             System.out.println("HTTP Status Code: " + ase.getStatusCode());
//             System.out.println("OOS Error Code:   " + ase.getErrorCode());
//             System.out.println("Request ID:       " + ase.getRequestId());
//
//         } catch (AmazonClientException ace) {
//             System.out.println("Caught an AmazonClientException, which means the client encountered "
//                     + "a serious internal problem while trying to communicate with OOS, "
//                     + "such as not being able to access the network.");
//             System.out.println("Error Message: " + ace.getMessage());
//         }
//     }
//
//     //101 分片上传
//     public static void testMultiUploadCopy(AmazonS3 ossClient) {
//         try {
//             String bucketName = myBucketName;
//             String key = "OOS开发者文档-v6 - 副本.pdf" ;
//             String uploadFile = "D:\\tmp\\test.zip";
//
//             // 通过UploadFileRequest设置多个参数
//             UploadFileRequest request = new UploadFileRequest(bucketName, key);
//
//             // 上传的本地文件
//             request.setUploadFile(uploadFile);
//
//             // 分片上传并发线程数，默认为1，最多为1000
//             request.setTaskNum(1);
//
//             // 每个分片的大小，默认5MB，若partSize小于5MB，除了最后一个分片以外，会将partSize调整至5MB
//             request.setPartSize(5 * 1024 * 1024);
//
//             // 开启断点续传功能，默认关闭
//             request.setEnableCheckpoint(true);
//             // 记录本地分片上传结果的文件。开启断点续传功能时需要设置此参数，上传过程中的进度信息会保存在该文件中，如果某一分片上传失败，再次上传时会根据文件中记录的点继续上传。
//             // 上传完成后，该文件会被删除。默认与待上传的本地文件同目录，为uploadFile.ucp
//             // request.setCheckpointFile("<yourCheckpointFile>");
//             MultipleUpload multiUpload = new MultipleUpload(request, ossClient);
//
//             // 断点续传上传
//             CompleteMultipartUploadResult result = multiUpload.upload();
//
//             String sourceKey1 = key;
//             String targetKey2 = "OOS开发者文档-copy.pdf";
//             CopyObjectRequest copyRequest = new CopyObjectRequest(
//                     bucketName,sourceKey1,bucketName,targetKey2);
//
//             ossClient.copyObject(copyRequest);
//
//             System.out.println("location:  "+result.getLocation());
//             System.out.println("Upload complete. Upload object name:" + result.getKey());
//         } catch (AmazonServiceException ase) {
//             System.out.println("Caught an AmazonServiceException, which means your request made it " + "to OOS, but was rejected with an error response for some reason.");
//             System.out.println("Error Message:    " + ase.getMessage());
//             System.out.println("HTTP Status Code: " + ase.getStatusCode());
//             System.out.println("OOS Error Code:   " + ase.getErrorCode());
//             System.out.println("Request ID:       " + ase.getRequestId());
//
//         } catch (AmazonClientException ace) {
//             System.out.println("Caught an AmazonClientException, which means the client encountered "
//                     + "a serious internal problem while trying to communicate with OOS, "
//                     + "such as not being able to access the network.");
//             System.out.println("Error Message: " + ace.getMessage());
//         }
//     }
//
//     //4.3.14 分段上传高级别API
//     public static void testTransferManager(AmazonS3 ossClient) throws Exception
//     {
//         String existingBucketName = "bkt-hhhhtest";
//         String keyName = "开发者指南-V6-PD06-1.pdf" ;
//         String filePath = "D:\\tmp\\2.txt";
//         TransferManager tm = new TransferManager(ossClient);
//         System.out.println("before upload");
//         // TransferManager processes all transfers asynchronously,
//         // so this call will return immediately.
//         Upload upload = tm.upload(
//                 existingBucketName, keyName, new File(filePath));
//
//         System.out.println("in upload");
//         try {
//             // Or you can block and wait for the upload to finish
//             upload.waitForCompletion();
//             System.out.println("Upload complete.");
//         } catch (AmazonClientException amazonClientException) {
//             System.out.println("Unable to upload file, upload was aborted.");
//             amazonClientException.printStackTrace();
//         }
//
//     }
//
//     public static void testAbortMultipartUploads(AmazonS3 ossClient) throws Exception
//     {
//         String existingBucketName = "bkt-hhhhtest";
//         TransferManager tm = new TransferManager(ossClient);
//         int sevenDays = 1000 * 60 * 60 * 24 * 7;
//         Date oneWeekAgo = new Date(System.currentTimeMillis() - sevenDays);
//         try {
//             tm.abortMultipartUploads(existingBucketName, oneWeekAgo);
//
//         } catch (AmazonClientException amazonClientException) {
//             System.out.println("Unable to upload file, upload was aborted.");
//             amazonClientException.printStackTrace();
//         }
//
//     }
//
//     public static AmazonS3 getAmazonS3(){
//         ClientConfiguration clientConfig = new ClientConfiguration();
//         clientConfig.setConnectionTimeout(30*1000);     //设置连接的超时时间，单位毫秒
//         clientConfig.setSocketTimeout(30*1000) ;        //设置socket超时时间，单位毫秒
//         clientConfig.setProtocol(Protocol.HTTP);        //设置http
//
//
//         //负载是否参与签名、设置参与
//         S3ClientOptions options = new S3ClientOptions();
//         options.setPayloadSigningEnabled(true);
//
//         /* 创建client*/
//         AmazonS3 ossClient = new AmazonS3Client(
//                 new PropertiesCredentials(TestConfig.OOS_ACCESS_ID, TestConfig.OOS_ACCESS_KEY),clientConfig);
//
//         // 设置endpoint
//         ossClient.setEndpoint(TestConfig.OOS_ENDPOINT);
//
//         //设置选项
//         ossClient.setS3ClientOptions(options);
//         return ossClient;
//     }
//
//     public static AmazonS3 getIamS3(){
//         ClientConfiguration clientConfig = new ClientConfiguration();
//         clientConfig.setConnectionTimeout(30*1000);     //设置连接的超时时间，单位毫秒
//         clientConfig.setSocketTimeout(30*1000) ;        //设置socket超时时间，单位毫秒
//         clientConfig.setProtocol(Protocol.HTTP);        //设置http
//
//
//
//         /* 创建client,其中OOSCredentials.properties中存放着用户名和密码*/
//         AmazonS3 ossClient = new AmazonS3Client(
//                 new PropertiesCredentials(TestConfig.OOS_ACCESS_ID, TestConfig.OOS_ACCESS_KEY),clientConfig);
//
//         // 设置endpoint IAM
//         ossClient.setEndpoint(TestConfig.OOS_ENDPOINT_ACCESS);
//
//         //负载是否参与签名、设置参与
//         S3ClientOptions options = new S3ClientOptions();
//         options.setPayloadSigningEnabled(false);
//         //设置选项
//         ossClient.setS3ClientOptions(options);
//         return ossClient;
//     }
//
//     public static AWSSecurityTokenServiceClient getStSClient(){
//         ClientConfiguration clientConfig = new ClientConfiguration();
//         clientConfig.setConnectionTimeout(30*1000);     //设置连接的超时时间，单位毫秒
//         clientConfig.setSocketTimeout(30*1000) ;        //设置socket超时时间，单位毫秒
//         clientConfig.setProtocol(Protocol.HTTP);        //设置http
//
//
//         /* 创建client,其中OOSCredentials.properties中存放着用户名和密码*/
//         AWSSecurityTokenServiceClient ossClient = new AWSSecurityTokenServiceClient(
//                 new PropertiesCredentials(TestConfig.OOS_ACCESS_ID, TestConfig.OOS_ACCESS_KEY),
//                 clientConfig);
//
//         // 设置endpoint IAM
//         ossClient.setEndpoint(TestConfig.OOS_ENDPOINT_ACCESS);
//
//
//         return ossClient;
//     }
//
//     public static AmazonS3 getAmazonS3_hwl(){
//         ClientConfiguration clientConfig = new ClientConfiguration();
//         clientConfig.setConnectionTimeout(30*1000);     //设置连接的超时时间，单位毫秒
//         clientConfig.setSocketTimeout(30*1000) ;        //设置socket超时时间，单位毫秒
//         clientConfig.setProtocol(Protocol.HTTP);        //设置http
//
//
//         //负载是否参与签名、设置参与
//         S3ClientOptions options = new S3ClientOptions();
//         options.setPayloadSigningEnabled(true);
//
//         /* 创建client*/
//         AmazonS3 ossClient = new AmazonS3Client(
//                 new PropertiesCredentials(TestConfig.OOS_ACCESS_ID_hwl, TestConfig.OOS_ACCESS_KEY_hwl),clientConfig);
//
//         // 设置endpoint
//         ossClient.setEndpoint(TestConfig.OOS_ENDPOINT);
//
//         //设置选项
//         ossClient.setS3ClientOptions(options);
//         return ossClient;
//     }
//
//     private void checkEndPoint() {
//         // TODO Auto-generated method stub
//         String line0 = "http://oos-tyz-6.ctyunapi.cn/";
//         String line = "httpsss://aa.com:1234";
//         String line2 = "http://aa.com:1234:12377";
//         String line3 = "http://aa.com:13";
//         String line4 = "https://aa.com:3456";
//
//         try {
//             checkValidEndPoint(line0);
//         } catch (Exception e) {
//             System.out.println(e.toString());
//         }
//         try {
//             checkValidEndPoint(line);
//         } catch (Exception e) {
//             System.out.println(e.toString());
//         }
//
//         try {
//             checkValidEndPoint(line2);
//         } catch (Exception e) {
//             System.out.println(e.toString());
//         }
//
//         try {
//             checkValidEndPoint(line3);
//         } catch (Exception e) {
//             System.out.println(e.toString());
//         }
//
//         try {
//             checkValidEndPoint(line4);
//         } catch (Exception e) {
//             System.out.println(e.toString());
//         }
//
//     }
//
//     private void checkValidEndPoint(String endPoint)  {
//
//         String pattern = "^[a-zA-Z]{4,5}://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(:\\d{1,5})?/?$";
//         Pattern r = Pattern.compile(pattern);
//         Matcher m = r.matcher(endPoint);
//         if (m.find()) {
//             String  foundStr = endPoint.substring(m.start(),  m.end());
//             System.out.println("Found string  is:" + foundStr);
//             //return true;
//         }
//         else {
//             throw new IllegalArgumentException("invalid endPoint:"+ endPoint);
//
//         }
//
//     }
//
//     private void testReg(String[] args) {
//         String regex   = "[a-z]@.";
//         Pattern p  = Pattern.compile(regex);
//         String str = "abc@yahoo.com,123@cnn.com,abc@google.com";
//         Matcher  m   = p.matcher(str);
//
//         while (m.find()) {
//             System.out.println("Matched  Text:" + m.group() + ", Start:" + m.start()
//                     + ", " + "End:" + m.end());
//         }
//     }
//
//     private void testReg2(String[] args) {
//         // A group of 3 digits followed by 7 digits.
//         String regex = "\\b(\\d{3})\\d{7}\\b";
//
//         // Compile the regular expression
//         Pattern p = Pattern.compile(regex);
//
//         String source = "12345678, 12345, and 9876543210";
//
//         // Get the Matcher object
//         Matcher m = p.matcher(source);
//
//         // Start matching and display the found area codes
//         while (m.find()) {
//             String phone = m.group();
//             String areaCode = m.group(1);
//             System.out.println("Phone: " + phone + ", Area  Code:  " + areaCode);
//         }
//     }
//
//     private static void putObjectWithSdk(AmazonS3 client, String bucketName, String objectName) throws IOException {
//         PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName,
//                 createSampleFile());
//         ObjectMetadata metadata = new ObjectMetadata();
//         metadata.setCacheControl("No-cache");
//         metadata.setContentDisposition("attachment; filename=testing.txt");
//         metadata.setContentEncoding("x-gzip");
//         metadata.setContentMD5("ICy5YqxZB1uWSwcVLSNLcA==");
//         metadata.setContentType("text/plain; charset=UTF-8");
//         metadata.addUserMetadata("test", "metadata");
//         metadata.setHttpExpiresDate(new Date());
//         metadata.setLastModified(new Date());
//         putObjectRequest.setMetadata(metadata);
//         client.putObject(putObjectRequest);
//
//     }
//
//     private static File createSampleFile() throws IOException {
//         File file = File.createTempFile("aws-java-sdk-", ".txt");
//         file.deleteOnExit();
//         Writer writer = new OutputStreamWriter(new FileOutputStream(file));
//         writer.write("123");
//         writer.close();
//         return file;
//     }
//
//     private static void testGetObject(AmazonS3 client, String bucketName, String objectName) throws IOException {
//         putObjectWithSdk(client,bucketName,objectName);
//         GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName,objectName);
//         S3Object object = new S3Object();
//         object = client.getObject(getObjectRequest);
//         System.out.println(object.getObjectMetadata().getContentLength()); //3
//         System.out.println(object.getObjectMetadata().getContentType());
//         System.out.println(object.getObjectMetadata().getETag()); // 202cb962ac59075b964b07152d234b70
//
//         System.out.println(object.getObjectMetadata().getHttpExpiresDate());
//
//         System.out.println("get object lastModified" + object.getObjectMetadata().getLastModified());
//         System.out.println(object.getObjectMetadata().getContentEncoding()); //"x-gzip");
//         System.out.println(object.getObjectMetadata().getContentDisposition()); // "attachment; filename=testing.txt");
//         System.out.println(object.getObjectMetadata().getContentMD5()); // "ICy5YqxZB1uWSwcVLSNLcA==");
//         client.deleteObject(bucketName,objectName);
//     }
//
//
//     // 测试接口4.4.6 Upload Part
//     public void testMultipartUpload(AmazonS3 oosClient) throws IOException {
//         String bucketName = TestConfig.bucketName;
//         String objectName = "multipart";
//         InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(
//                 bucketName, objectName);
//         InitiateMultipartUploadResult result = oosClient.initiateMultipartUpload(request);
//         UploadPartRequest request3 = new UploadPartRequest();
//         request3.setFile(createSampleFile());
//         request3.setPartNumber(1);
//         request3.setUploadId(result.getUploadId());
//         request3.setBucketName(bucketName);
//         request3.setKey(objectName);
//         request3.setPartSize(1);
//         UploadPartResult result3 = oosClient.uploadPart(request3);
//         //        AbortMultipartUploadRequest request2 = new AbortMultipartUploadRequest(
//         //                bucketName, objectName, result.getUploadId());
//         //        oosClient.abortMultipartUpload(request2);
//         List<PartETag> parts = new ArrayList<PartETag>();
//         PartETag e1 = new PartETag(1, result3.getPartETag().getETag());
//         parts.add(e1);
//         CompleteMultipartUploadRequest request4 = new CompleteMultipartUploadRequest(
//                 bucketName, objectName, result.getUploadId(), parts);
//         try {
//             oosClient.completeMultipartUpload(request4);
//         } catch (AmazonServiceException e) {
//             System.out.println(e.toString());
//
//         }
//     }
//
// }
//
